{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "244de831",
   "metadata": {},
   "source": [
    "________________\n",
    "* 2022/9/26/week06\n",
    "* Python学习记录\n",
    "________________"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70570838",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 随机函数\n",
    "\n",
    "> 2. 时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "825b67ed",
   "metadata": {},
   "source": [
    "## 1. 随机函数\n",
    "\n",
    "> 1. random.random(): 生成随机数，0-1之间随机数\n",
    "> 2. random.randint(): 生成随机数          \n",
    "> 3. random.choices(): 随机抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5e764b91",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bf8b8829",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function random:\n",
      "\n",
      "random() method of random.Random instance\n",
      "    random() -> x in the interval [0, 1).\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.random) # 0-1 float 小数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3acd0976",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.11398345641898311"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6e0a21f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method randint in module random:\n",
      "\n",
      "randint(a, b) method of random.Random instance\n",
      "    Return random integer in range [a, b], including both end points.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.randint) # 整数 integer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1e0c2aac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint (0,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "49b2d3ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "2\n",
      "4\n",
      "2\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "# randint小实践：大话骰\n",
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64e670d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# randint小实践：猜数字，0-100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "29e4539c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Xiaohong']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.choices(),在数据组（列表）随机选择一个值\n",
    "random.choices([\"Alex\",\"Xiaohong\",\"LiHua\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "15293a74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "77\n",
      "76\n",
      "55\n",
      "10\n",
      "57\n"
     ]
    }
   ],
   "source": [
    "# 通过随机值，大概去判断一下彩票的中奖概率\n",
    "# [12,34,65,10,22,12]\n",
    "for i in range(6):\n",
    "    print(random.randint(0,99))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b98626bd",
   "metadata": {},
   "source": [
    "## 2.时间函数 time()\n",
    "\n",
    "* 时间延迟函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fa700c1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "138bb90a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=26, tm_hour=10, tm_min=28, tm_sec=31, tm_wday=0, tm_yday=269, tm_isdst=0)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c41ed9a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sleep in module time:\n",
      "\n",
      "sleep(...)\n",
      "    sleep(seconds)\n",
      "    \n",
      "    Delay execution for a given number of seconds.  The argument may be\n",
      "    a floating point number for subsecond precision.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0aada7b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "time.sleep(2)\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d5bf6332",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据获取...\n",
      "页面停留 3 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 19 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 16 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 4 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 8 秒\n",
      "继续下一页..\n"
     ]
    }
   ],
   "source": [
    "# 实践：浏览抓取网页数据，模拟人的行为，让机器慢下来，每执行一次休息3秒钟。\n",
    "#      进阶：  随机产生一个数（3，50），让程序停留随机数的秒数\n",
    "for i in range(5):\n",
    "    print(\"数据获取...\")\n",
    "    wait_time = random.randint(3,20)\n",
    "    print(\"页面停留\",wait_time,\"秒\")\n",
    "    time.sleep(wait_time)\n",
    "    print(\"继续下一页..\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b659ddff",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 练习，课本P33  涉及知识点：模块，变量，条件判断，time模块，for循环\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "898b6b6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前是奇数秒 27\n",
      "等待时间(随机)： 4\n",
      "------------\n",
      "当前是奇数秒 31\n",
      "等待时间(随机)： 2\n",
      "------------\n",
      "当前是奇数秒 33\n",
      "等待时间(随机)： 2\n",
      "------------\n",
      "当前是奇数秒 35\n",
      "等待时间(随机)： 3\n",
      "------------\n",
      "当前是偶数秒 38\n",
      "等待时间(随机)： 1\n",
      "------------\n"
     ]
    }
   ],
   "source": [
    "# from datetime import datetime\n",
    "import datetime\n",
    "import time,random\n",
    "\n",
    "odds = [ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19,\n",
    "        21, 23, 25, 27, 29, 31, 33, 35,37, \n",
    "        39,41, 43, 45, 51, 53, 55, 57, 59 ]\n",
    "\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_seconds = datetime.datetime.today().second\n",
    "    if right_this_seconds in odds:\n",
    "        print(\"当前是奇数秒\",right_this_seconds)\n",
    "    else:\n",
    "        print(\"当前是偶数秒\",right_this_seconds)\n",
    "    wait_time = random.randint(1,5)\n",
    "    print(\"等待时间(随机)：\",wait_time)\n",
    "    time.sleep(wait_time)\n",
    "    print(\"------------\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b2cbad44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles 在啤酒墙上~~\n",
      "99 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "98 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "98 bottles 在啤酒墙上~~\n",
      "98 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "97 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "97 bottles 在啤酒墙上~~\n",
      "97 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "96 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "96 bottles 在啤酒墙上~~\n",
      "96 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "95 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "95 bottles 在啤酒墙上~~\n",
      "95 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "94 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "94 bottles 在啤酒墙上~~\n",
      "94 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "93 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "93 bottles 在啤酒墙上~~\n",
      "93 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "92 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "92 bottles 在啤酒墙上~~\n",
      "92 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "91 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "91 bottles 在啤酒墙上~~\n",
      "91 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "90 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "90 bottles 在啤酒墙上~~\n",
      "90 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "89 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "89 bottles 在啤酒墙上~~\n",
      "89 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "88 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "88 bottles 在啤酒墙上~~\n",
      "88 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "87 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "87 bottles 在啤酒墙上~~\n",
      "87 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "86 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "86 bottles 在啤酒墙上~~\n",
      "86 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "85 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "85 bottles 在啤酒墙上~~\n",
      "85 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "84 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "84 bottles 在啤酒墙上~~\n",
      "84 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "83 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "83 bottles 在啤酒墙上~~\n",
      "83 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "82 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "82 bottles 在啤酒墙上~~\n",
      "82 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "81 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "81 bottles 在啤酒墙上~~\n",
      "81 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "80 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "80 bottles 在啤酒墙上~~\n",
      "80 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "79 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "79 bottles 在啤酒墙上~~\n",
      "79 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "78 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "78 bottles 在啤酒墙上~~\n",
      "78 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "77 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "77 bottles 在啤酒墙上~~\n",
      "77 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "76 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "76 bottles 在啤酒墙上~~\n",
      "76 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "75 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "75 bottles 在啤酒墙上~~\n",
      "75 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "74 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "74 bottles 在啤酒墙上~~\n",
      "74 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "73 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "73 bottles 在啤酒墙上~~\n",
      "73 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "72 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "72 bottles 在啤酒墙上~~\n",
      "72 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "71 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "71 bottles 在啤酒墙上~~\n",
      "71 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "70 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "70 bottles 在啤酒墙上~~\n",
      "70 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "69 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "69 bottles 在啤酒墙上~~\n",
      "69 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "68 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "68 bottles 在啤酒墙上~~\n",
      "68 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "67 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "67 bottles 在啤酒墙上~~\n",
      "67 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "66 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "66 bottles 在啤酒墙上~~\n",
      "66 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "65 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "65 bottles 在啤酒墙上~~\n",
      "65 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "64 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "64 bottles 在啤酒墙上~~\n",
      "64 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "63 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "63 bottles 在啤酒墙上~~\n",
      "63 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "62 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "62 bottles 在啤酒墙上~~\n",
      "62 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "61 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "61 bottles 在啤酒墙上~~\n",
      "61 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "60 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "60 bottles 在啤酒墙上~~\n",
      "60 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "59 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "59 bottles 在啤酒墙上~~\n",
      "59 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "58 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "58 bottles 在啤酒墙上~~\n",
      "58 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "57 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "57 bottles 在啤酒墙上~~\n",
      "57 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "56 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "56 bottles 在啤酒墙上~~\n",
      "56 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "55 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "55 bottles 在啤酒墙上~~\n",
      "55 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "54 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "54 bottles 在啤酒墙上~~\n",
      "54 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "53 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "53 bottles 在啤酒墙上~~\n",
      "53 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "52 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "52 bottles 在啤酒墙上~~\n",
      "52 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "51 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "51 bottles 在啤酒墙上~~\n",
      "51 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "50 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "50 bottles 在啤酒墙上~~\n",
      "50 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "49 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "49 bottles 在啤酒墙上~~\n",
      "49 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "48 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "48 bottles 在啤酒墙上~~\n",
      "48 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "47 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "47 bottles 在啤酒墙上~~\n",
      "47 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "46 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "46 bottles 在啤酒墙上~~\n",
      "46 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "45 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "45 bottles 在啤酒墙上~~\n",
      "45 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "44 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "44 bottles 在啤酒墙上~~\n",
      "44 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "43 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "43 bottles 在啤酒墙上~~\n",
      "43 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "42 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "42 bottles 在啤酒墙上~~\n",
      "42 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "41 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "41 bottles 在啤酒墙上~~\n",
      "41 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "40 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "40 bottles 在啤酒墙上~~\n",
      "40 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "39 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "39 bottles 在啤酒墙上~~\n",
      "39 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "38 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "38 bottles 在啤酒墙上~~\n",
      "38 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "37 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "37 bottles 在啤酒墙上~~\n",
      "37 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "36 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "36 bottles 在啤酒墙上~~\n",
      "36 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "35 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "35 bottles 在啤酒墙上~~\n",
      "35 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "34 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "34 bottles 在啤酒墙上~~\n",
      "34 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "33 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "33 bottles 在啤酒墙上~~\n",
      "33 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "32 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "32 bottles 在啤酒墙上~~\n",
      "32 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "31 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "31 bottles 在啤酒墙上~~\n",
      "31 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "30 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "30 bottles 在啤酒墙上~~\n",
      "30 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "29 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "29 bottles 在啤酒墙上~~\n",
      "29 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "28 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "28 bottles 在啤酒墙上~~\n",
      "28 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "27 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "27 bottles 在啤酒墙上~~\n",
      "27 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "26 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "26 bottles 在啤酒墙上~~\n",
      "26 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "25 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "25 bottles 在啤酒墙上~~\n",
      "25 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "24 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "24 bottles 在啤酒墙上~~\n",
      "24 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "23 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "23 bottles 在啤酒墙上~~\n",
      "23 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "22 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "22 bottles 在啤酒墙上~~\n",
      "22 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "21 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "21 bottles 在啤酒墙上~~\n",
      "21 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "20 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "20 bottles 在啤酒墙上~~\n",
      "20 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "19 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "19 bottles 在啤酒墙上~~\n",
      "19 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "18 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "18 bottles 在啤酒墙上~~\n",
      "18 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "17 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "17 bottles 在啤酒墙上~~\n",
      "17 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "16 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "16 bottles 在啤酒墙上~~\n",
      "16 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "15 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "15 bottles 在啤酒墙上~~\n",
      "15 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "14 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "14 bottles 在啤酒墙上~~\n",
      "14 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "13 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "13 bottles 在啤酒墙上~~\n",
      "13 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "12 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "12 bottles 在啤酒墙上~~\n",
      "12 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "11 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "11 bottles 在啤酒墙上~~\n",
      "11 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "10 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "10 bottles 在啤酒墙上~~\n",
      "10 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "9 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "9 bottles 在啤酒墙上~~\n",
      "9 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "8 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "8 bottles 在啤酒墙上~~\n",
      "8 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "7 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "7 bottles 在啤酒墙上~~\n",
      "7 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "6 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "6 bottles 在啤酒墙上~~\n",
      "6 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "5 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "5 bottles 在啤酒墙上~~\n",
      "5 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "4 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "4 bottles 在啤酒墙上~~\n",
      "4 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "3 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "3 bottles 在啤酒墙上~~\n",
      "3 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "2 bottles 在啤酒墙上~~\n",
      "-----------\n",
      "2 bottles 在啤酒墙上~~\n",
      "2 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "1 bottle 在啤酒墙上~~\n",
      "-----------\n",
      "1 bottle 在啤酒墙上~~\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 bottle 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "只剩一瓶了，不能给你了，要放在墙上展示\n",
      "-----------\n"
     ]
    }
   ],
   "source": [
    "# 练习，课本P44  涉及知识点：模块，变量，条件判断，time模块，random模块，for循环\n",
    "beer_name = \"bottles\"\n",
    "\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,beer_name,\"在啤酒墙上~~\")\n",
    "    print(beer_num,beer_name, \"啤酒~~\") \n",
    "    print(\"拿下来一瓶给我吧~~\")\n",
    "    print(\"啤酒被拿走一瓶了~~\")\n",
    "    # 情况一：只剩一瓶的情况：\n",
    "    if beer_num == 1:\n",
    "        print(\"只剩一瓶了，不能给你了，要放在墙上展示\")\n",
    "    # 情况二： 还有多于1瓶的情况\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1 :\n",
    "            beer_name = \"bottle\"\n",
    "        print (new_num,beer_name,\"在啤酒墙上~~\")\n",
    "    print(\"-----------\")\n",
    "    \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7230adf4",
   "metadata": {},
   "source": [
    "## 3. 有序的数据结构（）\n",
    "> 1. 数值\n",
    "\n",
    "\n",
    "> 2. 字符串\n",
    "\n",
    "\n",
    "> 3. 列表，元组，字典，*集合 （期中考核）P144前"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c83ca8ee",
   "metadata": {},
   "source": [
    "## 3.0 数值的类型？\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "a2f2f751",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### 3.1 数值的基本运算 (Operation)\n",
    "\n",
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7b74e8a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "719f7a06",
   "metadata": {},
   "source": [
    "pd.read_html(\"https://docs.python.org/3.8/library/stdtypes.html#numeric-types-int-float-complex\")[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6f3afc4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "bdb3ffa3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.25"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3cb568ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17//4 # 取整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "afed1ed1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17%5 # 取余数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "a03baf10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**2 # 5的平方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "3f4e9583",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.23606797749979"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**(1/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "431a2c40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 & 3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79e3e617",
   "metadata": {},
   "source": [
    "### 3.2 数值的一般方法 （Methods)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "dfc35b69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x04\\x00'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1024).to_bytes(10,byteorder='big')  ## bytes 类型的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "f7d82311",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(2.0).is_integer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "21413449",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(2.5).is_integer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "12550904",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2.0.is_integer()  ##不加括号也行"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82b691c6",
   "metadata": {},
   "source": [
    "## 4.字符串\n",
    "\n",
    "* 课后：\n",
    "> 1. 什么是字符串？\n",
    "> 2. 字符串的一般表现形式？\n",
    "> 3. 字符串的运算有哪些？  譬如：+ 是什么意思，取值，切片，索引的概念是什么？\n",
    "> 4. 字符串的一般方法？  譬如： count(),in\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f250abca",
   "metadata": {},
   "source": [
    "### 字符串是由数字、字母、下划线组成的一串字符。一般记为 s=“a1a2...an”(n>=0)。它是编程语言中表示文本的数据类型。在程序设计中，字符串为符号或数值的一个连续序列，如符号串或二进制数字串。\n",
    "\n",
    "#### 第1种方式：使用单引号包含字符。如：\n",
    "'a' '111'  \n",
    "需要注意的是，单引号表示的字符串里面不能包含单引号，如let's go不能用单引号包含\n",
    "\n",
    "#### 第2种方式：使用双引号包含字符。如：\n",
    "\"a\"\"111\"  \n",
    "和第一种方法类似的是，双引号表示的字符串里不能包含双引号，并且只能有一行\n",
    "\n",
    "#### 第3种方式：使用三引号9(三对单引号或者三对双引号)包含字符。如：\n",
    "\"\"\"\n",
    "Hello,\n",
    "welcome to my new age...\n",
    "\"\"\"\n",
    "#或者：\n",
    "'''\n",
    "你好，\n",
    "欢迎来到我的新时代...\n",
    "'''\n",
    "需要注意的是，三个引号能包含多行字符串，并且常常出现在函数声明的下一行，用来注释函数的功能。与众不同的地方在于，这个注释作为函数的一个默认属性，可以通过“函数名.__doc__”进行访问。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5476150c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc55a9e5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
